<template>
    <div class="default-main ba-table-box">

        
        

        <!-- 表格顶部菜单 -->
        <!-- 自定义按钮请使用插槽，甚至公共搜索也可以使用具名插槽渲染，参见文档 -->
       

        <!-- 表格 -->
        <!-- 表格列有多种自定义渲染方式，比如自定义组件、具名插槽等，参见文档 -->
        <!-- 要使用 el-table 组件原有的属性，直接加在 Table 标签上即可 -->

        <div style="background: #fff; padding: 10px 10px;">
            <el-select v-model="state.search.year" style="width: 150px;" clearable :placeholder="t('请选择年份')">
                <el-option label="2021" value="2021" />
                <el-option label="2022" value="2022" />
                <el-option label="2023" value="2023" />
                    <el-option label="2024" value="2024" />
            </el-select>
            <el-select v-model="state.search.month" clearable :placeholder="t('请选择月份')" style="width: 150px;" class="ml-5">
                <el-option label="1" value="1" />
                <el-option label="2" value="2" />
                <el-option label="3" value="3" />
                <el-option label="4" value="4" />
                <el-option label="5" value="5" />
                <el-option label="6" value="6" />
                <el-option label="7" value="7" />
                <el-option label="8" value="8" />
                <el-option label="9" value="9" />
                <el-option label="10" value="10" />
                <el-option label="11" value="11" />
                <el-option label="12" value="12" />
            </el-select>
            <el-select v-model="state.search.dk_status" clearable :placeholder="t('状态')" style="width: 150px;" class="ml-5">
                <el-option :label="t('未打款')" value="0" />
                <el-option :label="t('已打款')" value="1" />
            </el-select>
            <span class="btn ml-5" @click="search">{{ t('搜索') }}</span>
        </div>

        <el-table :data="state.tableData" :span-method="mergeCells" class="my-table" :border="true">
            <el-table-column prop="create_time" :label="t('下单时间')" align="center" width="100"></el-table-column>
            <el-table-column prop="out_trade_no" :label="t('订单号')" align="center" width="170"></el-table-column>
            <el-table-column prop="profit" :label="t('纯利润')" align="center"></el-table-column>
            <el-table-column prop="name" :label="t('代理商')" align="center"></el-table-column>
            <el-table-column prop="commission_ratio" :label="t('佣金比率')" align="center"></el-table-column>
            <el-table-column prop="commission" :label="t('佣金')" align="center"></el-table-column>
            <el-table-column prop="commission_rate" :label="t('佣金税率')" align="center"></el-table-column>
            <el-table-column prop="commission_tax" :label="t('佣金税金')" align="center"></el-table-column>
            <el-table-column prop="to_commission" :label="t('应付佣金')" align="center"></el-table-column>
            <el-table-column prop="id" :label="t('打款状态')" align="center">
                <template #default="scope">
                    <el-text type="danger" style="font-size: 13px" v-if="scope.row.dk_status == 0">{{ t('未打款') }}</el-text>
                    <el-text type="success" style="font-size: 13px" v-if="scope.row.dk_status == 1">{{ t('已打款') }}</el-text>
                </template>
            </el-table-column>
            <el-table-column prop="dk_time" :label="t('时间')" align="center" width="100"></el-table-column>
            <el-table-column prop="id" :label="t('操作')" align="center">
                <template #default="scope">
                    <span class="btn btn-small" v-if="scope.row.dk_status == 0" @click="state.p1.id = scope.row.id; state.p1.agent_id = scope.row.agent_id">{{ t('打款') }}</span>
                    <el-popconfirm :title="t('确定取消打款吗') + '?'" v-if="scope.row.dk_status == 1" @confirm="qx(scope.row.agent_id)">
                        <template #reference>
                            <span class="btn btn-small">{{ t('取消') }}</span>
                        </template>
                    </el-popconfirm>
                </template>
            </el-table-column>
        </el-table>
        
        

        <!-- 表单 -->
        <!-- <PopupForm /> -->

        <P1 v-if="state.p1.id != 0" :data="state.p1" @closeP1="closeP1"  @load="load"/>


    </div>

    
</template>

<script setup lang="ts">
import { ref, provide, onMounted, reactive, toRefs } from 'vue'
import { useI18n } from 'vue-i18n'
import PopupForm from './popupForm.vue'
import P1 from './p1.vue'
import { cancelApi, indexApi } from '/@/api/most/finance/commission'



defineOptions({
    name: 'finance/account/index',
})

const { t } = useI18n()
const tableRef = ref()

const state = reactive({
    search: {
        year: '',
        month: '',
        dk_status: null,
        type: ''
    },
    admin: {},
    tableData: [],
    rowSpanArray: [], // 新增一个数组用于记录合并的行
    p1: {
        id: 0,
    }
})

const closeP1 = () => {
    state.p1.id = 0;
}

const qx = (id: number) => {
    cancelApi({id: id}).then((e) => {
        load();
    })
}


const mergeCells = ({ row, column, rowIndex }) => {
    if (column.property === 'create_time' || column.property === 'out_trade_no' || column.property === 'profit') {
        const currentColumn = column.property;
        // const prevColumn = currentColumn === 'create_time' ? 'out_trade_no' : 'create_time';
        const prevColumn = currentColumn == 'create_time' ? 'out_trade_no' : (currentColumn === 'out_trade_no' ? 'profit' : 'create_time');

        if (
            rowIndex === 0 ||
            row[currentColumn] !== state.tableData[rowIndex - 1][currentColumn] ||
            row[prevColumn] !== state.tableData[rowIndex - 1][prevColumn]
        ) {
            let rowspan = 1;

            for (let i = rowIndex + 1; i < state.tableData.length; i++) {
                if (
                    state.tableData[i][currentColumn] === row[currentColumn] &&
                    state.tableData[i][prevColumn] === row[prevColumn]
                ) {
                    rowspan++;
                } else {
                    break;
                }
            }

            return {
                rowspan,
                colspan: 1
            };
        } else {
            return {
                rowspan: 0,
                colspan: 0
            };
        }
    }
};

const load = () => {
    state.p1.id = 0;
    indexApi().then((response) => {
        state.tableData = response.data.list;
    });
    
}

onMounted(() => {
    indexApi().then((response) => {
        state.tableData = response.data.list;
    });
});



</script>

<style scoped lang="scss">

:deep(.my-table.el-table tr:hover) {
  background-color: transparent !important; /* 设置为透明 */
  color: inherit !important; /* 继承默认颜色 */
  /* 其他样式重置，根据需要调整 */
}
:deep(.el-table--enable-row-transition .el-table__body td.el-table__cell){
    background-color: transparent !important; /* 设置为透明 */
    color: inherit !important; /* 继承默认颜色 */
}
:deep(.el-table th.el-table__cell){
    background: #F5F5F6!important;
}

:deep(.el-table){
    // border-bottom: 1px solid #ddd;
}

:deep(.el-table thead){
    color: #333;
}
:deep(.el-table--border .el-table__cell){
    border-right: 1px #eee solid;
    border-bottom: 1px #eee solid;
}

:deep(.el-image){
    // width: 60px;
    // height: 60px;
    width: unset;
    height: unset;
    // max-height: 100px;
    // max-width: 80px;
    // max-height: 80px;
}
:deep(td.business-name > div.cell) {
    min-height: 80px;
    display:flex;
    justify-content:center; 
    align-items:center;
}
.tian{
    cursor: pointer;
}
.tian:hover{
    color: #409EFF;
}

:deep(.el-image > img){
    // width: 60px;
    // height: 60px;
    width: unset;
    height: unset;
    // max-height: 100px;
    max-width: 80px;
    max-height: 80px;
}
:deep(.ba-data-table .btn){
    padding: 4px 14px;
}


:deep(.ba-data-table .margin-left-none:last-child){
    margin-bottom: 0px;
}
:deep(.table-operate-text){
    padding-left: 0;
}
:deep(.font-size-13){
    font-size: 13px;
}
:deep(.pay-type .el-radio){
    margin-right: 10px;
}
pre{
    font-family: 'Helvetica Neue',Helvetica,'PingFang SC','Hiragino Sans GB','Microsoft YaHei','微软雅黑',Arial,sans-serif;
}
:deep(.ba-operate-dialog .el-dialog__body){
    padding-bottom: 0;
    padding-left: 0;
    padding-right: 0;
}
:deep(.quotation-scrollbar .el-scrollbar:first-child > .el-scrollbar__wrap){
    height: 100%;
}
:deep(.ml-0){
    margin-left: 0!important;
}
:deep(.mt-8){
    margin-top: 8px;
}
:deep(.ml--6){
    margin-left: -6px;
}
:deep(.ml-5){
    margin-left: 5px;
}
:deep(.mt-5){
    margin-top: 5px;
}
:deep(.el-button){
    height: unset;
}
:deep(.el-table__row.no-hover:hover .no-hover) {
  background-color: transparent!important; /* 使用 !important 来确保覆盖默认样式 */
  color: inherit !important;
//   background-color: red;
}
.tag{
    margin-right: 18px;
}

// .tag .active{
//     background: #ECF5FF;
//     color: #409EFF;
//     border: 1px solid #C6E2FF;
// }
:deep(.information .el-drawer__body){
    padding-top: 0;
}
:deep(.upload-column .el-form-item__label){
    display: none;
}
:deep(.upload-column .ba-upload.file){
    line-height: 8px;
}
:deep(.tag-0 .el-table td.el-table__cell, .el-table th.el-table__cell.is-leaf){
    border-top: 2px solid #efefef;
    border-right: 2px solid #efefef;

}

:deep(.information .el-table th.el-table__cell){
    background: rgb(245, 245, 246);
    color: #333;
    border-color: rgb(234, 234, 234);
}
:deep(.information .el-form--inline .el-form-item){
    margin-right: 23px;
}
:deep(.information .el-timeline-item){
    padding-bottom: unset;
}
:deep(.information .el-timeline-item__timestamp){
    font-size: 14px;
}
:deep(.el-button){
    height: unset;
}

:deep(.el-image > img){
    max-width: 50px;
    max-height: 50px;
}
:deep(.el-form--default.el-form--label-top .el-form-item .el-form-item__label){
    margin-bottom: 3px;
}
:deep(.information .el-drawer__header){
    margin-bottom: 17px!important;
}
:deep(.ml--6){
    margin-left: -1px;
}
</style>
